﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using Gameplay.PVE.Survivor;
using OWL.Rendering.HRP;
using UnityEditor;
using UnityEngine;
using Yoozoo.HRP.Runtime;
using Vector3 = UnityEngine.Vector3;

[CustomEditor(typeof(MapFogGroup))]
public class MapFogGroupInspector : Editor
{
    private MapFogGroup fogData;
    private List<bool> toggleTxt = new List<bool>();

    private void OnEnable()
    {
        fogData = target as MapFogGroup;
        toggleTxt.Clear();
        for (int i = 0; i < fogData.blocks.Count; i++)
        {
            toggleTxt.Add(false);
        }
    }

    public override void OnInspectorGUI()
    {
        if (GUILayout.Button("生成"))
        {
            fogData.GenerateImage();
            toggleTxt.Clear();
            for (int i = 0; i < fogData.blocks.Count; i++)
            {
                toggleTxt.Add(false);
            }
        }

        bool needRebuild = false;
        for (int i = 0; i < fogData.blocks.Count; i++)
        {
            var t = GUILayout.Toggle(toggleTxt[i], fogData.blocks[i].name);
            if (t != toggleTxt[i])
            {
                toggleTxt[i] = t;
                needRebuild = true;
            }
        }

        if (needRebuild)
        {
            var value = 0;
            for (int i = 0; i < fogData.blocks.Count; i++)
            {
                if (toggleTxt[i])
                {
                    value |= 1 << fogData.blocks[i].id;
                }
            }
            fogData.UnlockFog(value);
        }
        base.OnInspectorGUI();
    }
}